package com.my.study.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.my.study.excel.pojo.CompanyInfo;
import org.junit.Test;
import org.openjdk.jol.info.ClassLayout;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 带校验：https://www.jianshu.com/p/f3a9c9d43d83
 * 内存分析：https://blog.csdn.net/weixin_43133353/article/details/103646024
 *
 * @author Carlos
 * @version 1.0.0
 * @date 2022/3/5 7:58
 */
public class EasyExcelTest {


    @Test
    public void testRead() {
        String path = "D:/selfData/study/公司信息.xlsx";
        List<CompanyInfo> result = new ArrayList<>();
        ExcelReaderBuilder read = EasyExcel.read(path, CompanyInfo.class, new CompanyInfoListener(result));
        read.sheet(1).doRead();
        System.out.println(result);
    }


    @Test
    public void testMultiSheet() throws InterruptedException {
        String path = "D:/selfData/study/公司信息.xlsx";
        List<CompanyInfo> sheet0 = new ArrayList<>();
        List<CompanyInfo> sheet1 = new ArrayList<>();


        ExcelReader excelReader = null;

        try {
            excelReader = EasyExcel.read(path).build();
            ReadSheet readSheet0 = EasyExcel.readSheet(0).head(CompanyInfo.class)
                    .registerReadListener(new CompanyInfoListener(sheet0)).build();
            ReadSheet readSheet1 = EasyExcel.readSheet(1).head(CompanyInfo.class)
                    .registerReadListener(new CompanyInfoListener(sheet1)).build();

            excelReader.read(readSheet0, readSheet1);
        } finally {
            if (null != excelReader) {
                excelReader.finish();
            }
        }

        int size = sheet0.size();
    }

    @Test
    public void testCulB() {
        System.out.println(ClassLayout.parseClass(CompanyInfo.class).toPrintable());
//        System.out.println(ClassLayout.parseClass(HashMap.class).toPrintable());
//        System.out.println(ClassLayout.parseClass(CustomMap.Node.class).toPrintable());
    }

}
